package com.aglhz.nature.view;

import com.aglhz.nature.R;
import com.aglhz.nature.presenter.ChangePasswordPresenter;
import com.aglhz.nature.presenter.PersonDataPresenter;
import com.aglhz.nature.view.iv.ChangePasswordView;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class ChangePaswordActivity extends Activity implements ChangePasswordView{
	private SharedPreferences shPreferences;
	
	private ChangePasswordPresenter presenter;
	
	private EditText password_old_password;
	private EditText password_new_password;
	private Button password_bt_change;
	private String old_password;
	private String new_password;
	private TextView password_account;
	private ImageView back;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.changepassword);
		
		shPreferences= getSharedPreferences("EditText_Info",
				Context.MODE_PRIVATE);
		
		password_old_password=(EditText) findViewById(R.id.password_old_password);
		password_new_password=(EditText) findViewById(R.id. password_new_password);
		password_bt_change=(Button) findViewById(R.id.password_bt_change);
		back=(ImageView) findViewById(R.id.back);
		password_account=(TextView) findViewById(R.id.password_account);
		password_account.setText(shPreferences.getString("NORMAL_ACCOUNT", ""));
		back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
			finish();
				
			}
		});
		
		presenter = new ChangePasswordPresenter(this,ChangePaswordActivity.this);
		// basePresenter register
		presenter.register();
		password_bt_change.setOnClickListener(new OnClickListener() {	
			@Override
			public void onClick(View arg0) {
				old_password=password_old_password.getText().toString().trim();
				new_password=password_new_password.getText().toString().trim();
			presenter.loadChangePasswordBean();
				
			}
		});
		
		
	}
	@Override
	public String setOld_password() {
		return old_password;
	}
	@Override
	public String setNew_password() {
		return new_password;
	}
	@Override
	public String setOk_password() {
		return new_password;
	}
	@Override
	public void showSucessToast() {
		Toast.makeText(ChangePaswordActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
		
	}
	@Override
	public void showFailureToast() {
		Toast.makeText(ChangePaswordActivity.this, presenter.setFailureMessage(), Toast.LENGTH_SHORT).show();
		
	}
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		presenter.unregister();
	}
}
